﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DaoShopOnline
{
    public class ManageProducts
    {
        private ShopOnlineDataContext context;

        public ManageProducts()
        {
            this.context = new ShopOnlineDataContext();
        }

        public IQueryable<Product> GetAllProducts()
        {
            return this.context.Products;
        }



        public void EditProduct(Product product)
        {
            Product productToEdit = (from prod in this.context.Products
                                     where prod.ProductID == product.ProductID
                                     select prod).SingleOrDefault();
            productToEdit.ProductName = product.ProductName;
            productToEdit.CategoryID = product.CategoryID;
            productToEdit.Description = product.Description;
            productToEdit.Photo = product.Photo;
            productToEdit.Price = product.Price;
            this.context.SubmitChanges();
        }

        public void DeleteProduct(Product product)
        {
            this.context.Products.DeleteOnSubmit(product);
            this.context.SubmitChanges();
        }

        public void AddProduct(Product product)
        {
            this.context.Products.InsertOnSubmit(product);
            this.context.SubmitChanges();
        }
    }
}
